package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CheckStandard;
import com.ruoyi.system.service.ICheckStandardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检验标准Controller
 * 
 * @author ruoyi
 * @date 2023-11-02
 */
@RestController
@RequestMapping("/system/standard")
public class CheckStandardController extends BaseController
{
    @Autowired
    private ICheckStandardService checkStandardService;

    /**
     * 查询检验标准列表
     */
    @PreAuthorize("@ss.hasPermi('system:standard:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckStandard checkStandard)
    {
        startPage();
        List<CheckStandard> list = checkStandardService.selectCheckStandardList(checkStandard);
        return getDataTable(list);
    }

    /**
     * 导出检验标准列表
     */
    @PreAuthorize("@ss.hasPermi('system:standard:export')")
    @Log(title = "检验标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckStandard checkStandard)
    {
        List<CheckStandard> list = checkStandardService.selectCheckStandardList(checkStandard);
        ExcelUtil<CheckStandard> util = new ExcelUtil<CheckStandard>(CheckStandard.class);
        util.exportExcel(response, list, "检验标准数据");
    }

    /**
     * 获取检验标准详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:standard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(checkStandardService.selectCheckStandardById(id));
    }

    /**
     * 新增检验标准
     */
    @PreAuthorize("@ss.hasPermi('system:standard:add')")
    @Log(title = "检验标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckStandard checkStandard)
    {
        return toAjax(checkStandardService.insertCheckStandard(checkStandard));
    }

    /**
     * 修改检验标准
     */
    @PreAuthorize("@ss.hasPermi('system:standard:edit')")
    @Log(title = "检验标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckStandard checkStandard)
    {
        return toAjax(checkStandardService.updateCheckStandard(checkStandard));
    }

    /**
     * 删除检验标准
     */
    @PreAuthorize("@ss.hasPermi('system:standard:remove')")
    @Log(title = "检验标准", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(checkStandardService.deleteCheckStandardByIds(ids));
    }
}
